package com.netbao.ins.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.netbao.ins.model.Insurance;
import com.netbao.ins.model.InsuranceVo;
import com.netbao.ins.service.InsuranceService;
import com.netbao.ins.vomapper.InsuranceVoMapper;
import com.netbao.model.PageBean;
import com.netbao.model.PageResult;
import com.netbao.model.Result;
import com.netbao.sys.model.Dict;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Duanps
 * @create 2019-11-04 19:36
 */
@Service
public class InsuranceServiceImpl implements InsuranceService {
    @Resource
    private InsuranceVoMapper voMapper;

    @Override
    public PageResult findAll(PageBean pageBean, String cno, String idCard) {
        if(!StringUtils.isEmpty(idCard)){
            PageHelper.startPage(pageBean.getPage(), pageBean.getRows());
            PageInfo<InsuranceVo> pageInfo = new PageInfo<>(voMapper.mo(idCard));
            return new PageResult(pageInfo.getTotal(), pageInfo.getList());
        }
        PageHelper.startPage(pageBean.getPage(), pageBean.getRows());
        PageInfo<InsuranceVo> pageInfo = new PageInfo<>(voMapper.findAll(cno, idCard));
        return new PageResult(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public List<Insurance> getInsuList() {
        return voMapper.getInsuList();
    }

    @Override
    public Result getInsuListData(Integer id) {
        return Result.ok(voMapper.getInsuListData(id));
    }

    @Override
    public List<Dict> getInsuranceYear() {
        return voMapper.getInsuranceYear();
    }

    @Override
    public List<Dict> getInsuranceType() {
        return voMapper.getInsuranceType();
    }

    @Override
    public List<Dict> getInsuranceCompany() {
        return voMapper.getInsuranceCompany();
    }

    @Override
    public Result addInsInfo(Insurance insurance) {
        return Result.ok("添加成功", voMapper.insertSelective(insurance));
    }

    @Override
    public Result delete(Long id) {
        return Result.ok(voMapper.deleteByPrimaryKey(id));
    }

}
